package com.google.code.swingonfire.showcase.graphic.sketch;

import java.awt.Component;

import javax.swing.BorderFactory;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;

import com.google.code.swingonfire.builder.JLabelBuilder;

public class SketchListCellRenderer implements ListCellRenderer
{

    private final JLabel label;

    public SketchListCellRenderer()
    {
        super();

        label = new JLabelBuilder().opaque(true).border(BorderFactory.createEmptyBorder(4, 8, 4, 8)).build();
    }

    @Override
    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected,
        boolean cellHasFocus)
    {
        SketchSample sample = (SketchSample) value;

        label.setText(sample.toString());

        if (isSelected)
        {
            label.setForeground(list.getSelectionForeground());
            label.setBackground(list.getSelectionBackground());
        }
        else
        {
            label.setForeground(list.getForeground());
            label.setBackground(list.getBackground());
        }

        return label;
    }
}
